package com.lolongmaps.main;

import com.lolongmaps.model.User;
import com.lolongmaps.test.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.Spinner;

public class StartView extends Activity implements OnItemSelectedListener{
  
	/** Called when the activity is first created. */

	Spinner priceSpinner;
	ArrayAdapter<String> adapter;
	ImageButton confirmButton;
	Intent intent;
	Class suggestionClass;
	User user;
	
	String[] prices = {"50", "100", "150", "200"};
	int spinnerSelectedPosition;
	
	@Override
    public void onCreate(final Bundle savedInstanceState) {
		
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        adapter = new ArrayAdapter<String>(StartView.this, android.R.layout.simple_spinner_dropdown_item, prices);
        
        priceSpinner = (Spinner) findViewById(R.id.startSpinnerPrice);
        priceSpinner.setAdapter(adapter);
        priceSpinner.setOnItemSelectedListener(this);
        
        confirmButton = (ImageButton) findViewById(R.id.startButtonConfirm);
        
        confirmButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					
					suggestionClass = Class.forName("com.lolongmaps.main.SuggestionView");
					intent = new Intent(StartView.this, suggestionClass);
					intent.putExtra("userObject", user);
					startActivity(intent);
					
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}

	@Override
	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		
		this.spinnerSelectedPosition = this.priceSpinner.getSelectedItemPosition();
		this.user = new User(this.prices[this.spinnerSelectedPosition]);
		
	}

	
	
	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
	
	}
}